export const joinChannnel = ({
  rtc,
  appid,
  token,
  channel
}) => (dispatch) => {
  rtc.joinChannel({
    appid,
    token,
    uid: null,
    channel
  }).then(() => {
    rtc.publishStream().then((res) => {
      dispatch({
        type: 'STREAM_SUCCESS',
        data: res
      });
    }).catch((err) => {
      alert('Publish Failure');
    })
  }).catch((err) => {
    alert('Join Failure');
  })
}

export const leaveChannel = (rtc) => (dispatch) => {
  rtc.leaveChannel().then(() => {
    dispatch({
      type: 'CLEAR_STREAM'
    })
  }).catch((err) => {
    message.error('Leave Failure')
  })
}
